package com.yanqu.road.server.cmd.activity.fanxiuspring;

import com.yanqu.road.entity.activity.fanxiuspring.FanXiuSpringConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FanxiuspringProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.fanxiuspring.FanXiuSpringModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.fanxiuspring.FanXiuSpringMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_FAN_XIU_SPRING_LIGHT_UP, desc = "共庆点亮")
public class FanXiuSpringLightUpCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        // 没有活动
        FanXiuSpringConfig config = FanXiuSpringMgr.getActivityConfig(FanXiuSpringMgr.CHILD_TYPE_OTHER);
        if (config == null || !ActivityMgr.activityInTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
        FanxiuspringProto.FanXiuSpringLightUpReqMsg reqMsg = FanxiuspringProto.FanXiuSpringLightUpReqMsg.parseFrom(packet.getBytes());

        ret = player.getModule(FanXiuSpringModule.class).lightUp(reqMsg.getPosition());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_FAN_XIU_SPRING_LIGHT_UP, FanxiuspringProto.FanXiuSpringLightUpRespMsg.newBuilder().setRet(ret));
        }
    }
}
